package chapter3.No3_1_等待和通知机制.c等待通知机制的实现.demo4;

/**
 * Created by Administrator on 2016/11/16.
 */
public class ThreadA extends Thread {
    MyList list;

    public ThreadA(MyList list) {
        this.list = list;
    }

    @Override
    public void run() {
        try {
            synchronized (list) {
                for (int i = 0; i < 10; i++) {
                    Thread.sleep(500);
                    list.add();
                    if(list.size() == 5) {
                        list.notify();
                        System.out.println("已经到了5个了，通知对方");
                    }
                    System.out.println("添加了"+(i+0)+"个元素");
                }
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
